package com.powerwyx.shortlink.admin.controller;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.powerwyx.shortlink.admin.common.convention.result.Result;
import com.powerwyx.shortlink.admin.remote.ShortLinkActualRemoteService;
import com.powerwyx.shortlink.admin.remote.dto.ShortLinkGroupStatsAccessRecordDTO;
import com.powerwyx.shortlink.admin.remote.dto.ShortLinkGroupStatsDTO;
import com.powerwyx.shortlink.admin.remote.dto.ShortLinkStatsAccessRecordDTO;
import com.powerwyx.shortlink.admin.remote.dto.ShortLinkStatsDTO;
import com.powerwyx.shortlink.admin.remote.vo.ShortLinkStatsAccessRecordVO;
import com.powerwyx.shortlink.admin.remote.vo.ShortLinkStatsVO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * @author 王艺锡
 * @version 1.0
 */
@RestController
public class ShortLinkStatsController {
    @Autowired
    private ShortLinkActualRemoteService shortLinkActualRemoteService;


    /**
     * 访问单个短链接指定时间内监控数据
     */
    @GetMapping("/api/short-link/admin/v1/stats/getSingleStats")
    public Result<ShortLinkStatsVO> shortLinkStats(ShortLinkStatsDTO shortLinkStatsDTO) {
        return shortLinkActualRemoteService.shortLinkStats(
                shortLinkStatsDTO.getFullShortUrl(),
                shortLinkStatsDTO.getGid(),
                shortLinkStatsDTO.getEnableStatus(),
                shortLinkStatsDTO.getStartDate(),
                shortLinkStatsDTO.getEndDate()
                );
    }

    /**
     * 访问分组短链接指定时间内监控数据
     */
    @GetMapping("/api/short-link/admin/v1/stats/group")
    public Result<ShortLinkStatsVO> groupShortLinkStats(ShortLinkGroupStatsDTO shortLinkGroupStatsDTO) {
        return shortLinkActualRemoteService.groupShortLinkStats(
                shortLinkGroupStatsDTO.getGid(),
                shortLinkGroupStatsDTO.getStartDate(),
                shortLinkGroupStatsDTO.getEndDate()
        );
    }



    /**
     * 访问单个短链接指定时间内访问记录监控数据
     */
    @GetMapping("/api/short-link/admin/v1/stats/accessrecord")
    public Result<Page<ShortLinkStatsAccessRecordVO>> shortLinkStatsAccessRecord(ShortLinkStatsAccessRecordDTO shortLinkStatsAccessRecordDTO) {
        return shortLinkActualRemoteService.shortLinkStatsAccessRecord(
                shortLinkStatsAccessRecordDTO.getFullShortUrl(),
                shortLinkStatsAccessRecordDTO.getGid(),
                shortLinkStatsAccessRecordDTO.getStartDate(),
                shortLinkStatsAccessRecordDTO.getEndDate(),
                shortLinkStatsAccessRecordDTO.getEnableStatus(),
                shortLinkStatsAccessRecordDTO.getCurrent(),
                shortLinkStatsAccessRecordDTO.getSize()
        );
    }


    /**
     * 访问分组短链接指定时间内访问记录监控数据
     */
    @GetMapping("/api/short-link/admin/v1/stats/accessrecord/group")
    public Result<Page<ShortLinkStatsAccessRecordVO>> groupShortLinkStatsAccessRecord(ShortLinkGroupStatsAccessRecordDTO shortLinkGroupStatsAccessRecordDTO) {
        return shortLinkActualRemoteService.groupShortLinkStatsAccessRecord(
                shortLinkGroupStatsAccessRecordDTO.getGid(),
                shortLinkGroupStatsAccessRecordDTO.getStartDate(),
                shortLinkGroupStatsAccessRecordDTO.getEndDate(),
                shortLinkGroupStatsAccessRecordDTO.getCurrent(),
                shortLinkGroupStatsAccessRecordDTO.getSize()
        );
    }
}
